﻿using B.S.DataBase.MyProject.Domain.SalesReports;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Read.API.Applicantions.Command.MyOrdermementCommands;
using T.E.ERP.Read.API.Dtos.Dtos;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.MyOrdermementHandlers
{
    public class SaleReturnsoneHandler : IRequestHandler<SaleReturnsoneCommand, APIResult<List<string>>>
    {
        private readonly IBaseRepository<SalesReturns> _salesReturns;

        public SaleReturnsoneHandler(IBaseRepository<SalesReturns> salesReturns)
        {
            _salesReturns = salesReturns;
        }

        public async Task<APIResult<List<string>>> Handle(SaleReturnsoneCommand request, CancellationToken cancellationToken)
        {
            var result = new APIResult<List<string>>()
            {
                Code = APIEnum.查询成功,
                Msg = APIEnum.查询成功.ToString()
            };

            // 获取所有不重复的客户名称
            var clientNames = _salesReturns.GetAll().Result
                .Select(x => x.ClientName)
                .Distinct()
                .ToList();

            result.data = clientNames;
            return await Task.FromResult(result);

        }
    }
}
